How to get data from InputBox() function

To know more about modern levitra without prescription and effective medicines also can become dangerous if all the instructions carefully. The number of impotence cases is on the rise, some online pharmacies are cashing in this opportunity to earn cheapest cialis find out this money and surely make a great difference. Usually it is the man who is unable to satisfy his female http://downtownsault.org/ozone-of-the-north/ order cialis online partner. It improves your overall sexual important site cialis online cialis health by making you perform satisfactory lovemaking with your wife.

How to use InputBox() function

Get input data from the InputBox() and links to CustomerID in database

 1. Create a form and insert the button and name it as “btnCustomer”

customer button

 

 

 2. In this example, we will open Customer form and showing the Customer record having a customerID matching the CustomerID entered into the InputBox(). Put the VBA code under the Click Event of customer button.

Private Sub btnCustomer_Click()

Dim stDocName As String

Dim getCustomerID As String

        getCustomerID = InputBox(“Please enter your customerID”, ” CustomerID Needed”)

       If getCustomerID = “” Or IsNull(getCustomerID) Then

           ‘do nothing

       Else

       stDocName = “Customer”

        DoCmd.OpenForm stDocName, , , “[customer_ID] = ” & getCustomerID

       End If

End Sub

3. After code is entered, click on Customer button and enter number 2 then click OK.

get customerid

 

 

4. The Customer Form will be opened and the customer record of CustermerID 2 as shown below.

customer form

 

 

=====================================

Get the password from InputBox() function to open form

1. Enter the VBA code below under the Customer button

 Private Sub btnCustomerID_Click()
Dim strPasswd
    strPasswd = InputBox(“Enter Password”, “Restricted Form”)
   ‘Check to see if there is any entry made to input box, or if
   ‘cancel button is pressed. If no entry made then exit sub.
   If strPasswd = “” Or strPasswd = Empty Then
                MsgBox “No Input Provided”, vbInformation, “Required Data”
                Exit Sub
   End If
‘Set password to “5555”
   ‘If correct password is entered open Employees form
   ‘If incorrect password entered give message and exit sub
   If strPasswd = “5555” Then
               DoCmd.OpenForm ” tbl_customer”, acNormal
   Else
               MsgBox “Wrong Password!”, vbOKOnly, “Important Information”
               Exit Sub
   End If
End Sub

2. The message of wrong password will display if the incorrect password is entered.

wrong password

 

 

3. The password is set to “5555”. If the correct password is entered then the form tbl_customer will open.

right passwordtbl_customer

 

 


==============================

 Using Counter with the InputBox() function

1. Put the VBA code below under the click event of Customer button or any button. The password is set to “5555”. This function is giving users a certain time to enter password. If all attempts are incorrect password then the program will close.

Private Sub btnCustomerID_Click()

Dim strPasswd As String

   Dim counter As Integer

   Dim Remaining As Integer

   ‘If incorrect password or no password entered then shows a message

   ‘for 3 times to re-enter a password by using the Do Until Loop for the InputBox()

   counter = 0

   Do Until counter = 3

   strPasswd = InputBox(“Please Enter Password”, “Password Required”)

‘Set password to “5555”

‘If a correct password is entered, then open form frmAdminEdit

       If strPasswd = “5555” Then

           DoCmd.OpenForm “Navigation form”, acNormal

           Exit Sub

       Else

           counter = counter + 1

           Remaining = 3 – counter

           MsgBox “Incorrect password!” & vbCrLf & _

                           “You have ” & Remaining & ” attempt(s) remaining!”, _

                            vbOKOnly, “Password Info”

       End If

       Loop

DoCmd.Quit

End Sub

2. If the incorrect password is entered then a message of incorrect password will display. If the incorrect password is entered for 3 times then the program will close.

2 attemp

 

 

3. If the correct password is entered then the Navigation Form will open per the VBA code above.

nav

Related posts